<template>
    <div>
        <h2>管理员登陆(病房)</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">医生姓名</td>
                    <td>
                        <input type="text" v-model="info.SirName"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">头像</td>
                    <td>
                         <input type="file" @change="img"></input>
                         <img :src="info.pic" width="100" height="100" v-if="info.pic!=''">
                    </td>
                </tr>
                 <tr>
                    <td align="right">科室</td>
                    <td>
                                <select v-model="info.KeId">
                                    <option value="">请选择</option>
                                    <option :value="item.Id" v-for="item in list">{{ item.KeName }}</option>
                                </select>
                    </td>
                </tr>
                 <tr>
                    <td align="right">创建时间</td>
                    <td>
                         <input type="date" v-model="info.CreateTime"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="确定" class="btn btn-primary" @click="ok"></input>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from "axios";
import moment from "moment";
import {ref,reactive,onMounted} from "vue"
import {useRoute,useRouter} from "vue-router"
import {useStore} from "@/stores/user"

const route = useRoute();
const router = useRouter();
const abc = useStore();

let info:any = reactive({
  SirName: '',
  pic: '',
  KeId: '',
  CreateTime: '',
})

const ok=()=>{
    if(info.SirName==""){
        alert('医生名称不能为空');
        return
    }
    if(info.pic==""){
        alert('请上传图片');
        return
    }
    if(info.KeId==""){
        alert('请选择科室');
        return
    }
    if(info.CreateTime==""){
        alert('请确定时间');
        return
    }
    axios({
        url:'/api/YeHotels/Login',
        method:'post',
        data:info
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('已有该医生 请重新添加');
            return;
        }
        if(res.data>0){
            alert('添加成功');
            router.push("/sirShow")
            return;
        }
        alert('添加失败');
        return;
    })
    .catch(err=>{
        console.log(err);
        
    })
}

const img=(e:any)=>{
    console.log(e);
    let obj = e.target.files[0];
    let f = new FormData;
    
    axios({
        url:'/api/YeHotels/Img',
        method:'post',
        data:f
    })
     .then(res=>{
        console.log(res);
        if(res.data=='不是图片'){
            alert('您上传的不是图片');
            return;
        }
        if(res.data=='大于2M'){
            alert('您上传的图片大于2M');
            return;
        }
        info.pic = res.data
        return;
    })
    .catch(err=>{
        console.log(err);
        
    })
}

let list:any = ref([])

onMounted(()=>{
        getkeroom();
})
const getkeroom=()=>{
    axios({
        url:'/api/YeHotels/GetKeRooms',
        method:'get',
    })
    .then(res=>{
        console.log(res);
        list.value = res.data
    })
    .catch(err=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>